﻿using System;
using RAP.Framework.Libary.Utils;

namespace RAP.Framework.Libary.DomTemplateBuilder.Element.Conditional
{
	public class CompareBase : ConditionalBase
    {
		protected string _compareProperty = string.Empty;
        /// <summary>
        /// 要比较的属性
        /// </summary>
        public virtual string CompareProperty
        {
            get
            {
				if ( _compareProperty.IsNullOrEmpty ( ) )
				{
					_compareProperty = this.ToString ( "CompareProperty" );
				}
				return _compareProperty;
            }
            set
            {
				this[ "CompareProperty" ] = _compareProperty = value;
            }
        }


		protected PropertyValueStyles? _compareValueStyle;
        /// <summary>
        /// 被比较属性的来源类型（根参数对象、上下文对象）
        /// </summary>
		public virtual PropertyValueStyles CompareValueStyle
        {
            get
            {
                if ( _compareValueStyle == null )
                {
                    _compareValueStyle = this.ToString ( "CompareValueStyle" ).ToEnumValue<PropertyValueStyles> ( PropertyValueStyles.RootObject );
                }
                return _compareValueStyle.Value;
            }
        }

		protected string _compareValue = string.Empty;
        /// <summary>
        /// 要比较的值
        /// </summary>
		public virtual string CompareValue
        {
            get
            {
				if ( _compareValue.IsNullOrEmpty ( ) )
				{
					_compareValue = this.ToString ( "CompareValue" );
				}
				return _compareValue;
            }
            set
            {
				this[ "CompareValue" ] = _compareValue = value;
            }
        }

		protected TypeCode? _compareValueType = null;
		public virtual TypeCode CompareValueType
		{
			get
			{
				if ( this._compareValueType == null )
				{
					lock ( this )
					{
						if ( this._compareValueType == null )
						{
							_compareValueType = this.ToEnumValue<TypeCode> ( "CompareValueType", TypeCode.Empty );
						}
					}
				}
				return _compareValueType.Value;
			}
		}
    }
}
